package hu.bme.mit.rifl.business.monitor;

import hu.bme.mit.rifl.business.base.RiflOrderQueue;
import hu.bme.mit.rifl.business.base.WFElement;

/**
 * A monitoring node which traces the finished work items, i.e. the Orders
 * already passed through the entire workflow. Checks the size of the
 * FinishedOrderQueue and compares it to the lastItemNumber property; if the
 * result is more than the one stored in the lastItemNumber, the queue is
 * getting polled and the lastItemNumber property is incremented.
 */
public class FinishedOrderMonitor extends WFElement {

	/**
	 * Default constructor of the node. Sets the name and the input queue. 
	 */
	public FinishedOrderMonitor() {
		//The name of the window displayed on the GUI
		super("FinishedOrderMonitor");
		//The auto-execution is selected by default
		this.gui.setAutoSelected(true);
		//The input queue
		inputs.add(new RiflOrderQueue("rifl.finished"));
	}

	public static void main(String[] args) {
		FinishedOrderMonitor node = new FinishedOrderMonitor();
		node.run();
	}

	/**
	 * No actual business logic this time, since it's a diagnostical node, not a
	 * business one.
	 */
	@Override
	public void process() {
	}

	/**
	 * Overridden log method. The information is viewed on the console and in
	 * the monitoring window.
	 */
	@Override
	protected void LogResult() {
		String log = "";
		log = log + "\n";
		log = log + "Finished Order process. OrderID:" + order.getOrderID()
				+ ". State: " + order.getState() + ".";

		System.out.println(log);
		gui.log(log);
	}
	
	@Override
	protected void finish() {
		this.order = null;
	}
}
